package com.example.demozy.service;

import com.example.demozy.entity.CommodityCheck;
import com.example.demozy.entity.ConditionSheetCommodity;
import com.example.demozy.entity.ConditionSheetOperationData;
import com.example.demozy.entity.Order;
import com.example.demozy.mapper.ConditionSheetCommodityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 陆智荣
 */
@Service
public class ConditionSheetCommodityService {
    // **************** 公开变量

    // **************** 私有变量

    @Autowired
    private ConditionSheetCommodityMapper conditionSheetCommodityMapper;

    // **************** 继承方法

    // **************** 公开方法

    /**
     *获取所有商品信息
     */
    public List<ConditionSheetCommodity> selectCommodity() {
        return conditionSheetCommodityMapper.selectCommodity();
    }

    /**
     * 根据user_id获取用户
     * @param commodityId
     * @return
     */
    public ConditionSheetCommodity getConditionSheetCommodityById(String commodityId){
        return conditionSheetCommodityMapper.getConditionSheetCommodityById(commodityId);
    }

    /**
     *根据commodity_id获取用户个人简介
     * @param commodityId
     * @return
     */
    public String getUserDescriptionByCommodityId(String commodityId){
        return conditionSheetCommodityMapper.getUserDescriptionByCommodityId(commodityId);
    }

    /**
     *根据commodity_id获取用户昵称
     * @param commodityId
     * @return
     */
    public String getUserNicknameByCommodityId(String commodityId){
        return conditionSheetCommodityMapper.getUserNicknameByCommodityId(commodityId);
    }

    /**
     *获取商品所有运营数据
     */
    public ConditionSheetOperationData selectConditionSheetOperationDataCommodity(String commodityId) {
        return conditionSheetCommodityMapper.selectConditionSheetOperationData(commodityId);
    }

    /**
     * 更新商品的PV运营数据
     */
    public void insertConditionSheetOperationData(String commodityId){
        conditionSheetCommodityMapper.insertConditionSheetOperationData(commodityId);
    }

    /**
     *根据commodity_id获取用户ID
     * @param commodityId
     */
    public String getUserIdByCommodityId(String commodityId){
        return conditionSheetCommodityMapper.getUserIdByCommodityId(commodityId);
    }

    /**
     *根据commodity_id进行商品购买
     * @param commodityId
     * @param userId
     */
    public void purchaseCommodityByCommodityId(String commodityId,String userId){
        conditionSheetCommodityMapper.purchaseCommodityByCommodityId(commodityId, userId);
    }

    /**
     *搜索用户余额
     * @param userId
     */
    public double selectUserBalance (String userId){
        return conditionSheetCommodityMapper.selectUserBalance(userId);
    }

    /**
     *插入购买数据至订单表
     */
    public void insertOrder(String userId, String commodityId, double goodsPrice){
        conditionSheetCommodityMapper.insertOrder(userId, commodityId, goodsPrice);
    }

    /**
     *搜索订单表的商品id
     */
    public List<String> selectOrderCommodityId(String userId, String commodityId){
        return conditionSheetCommodityMapper.selectOrderCommodityId(userId, commodityId);
    }

    /**
     * 获取所有状态为未审核的条件单
     * @author 陆智荣
     */
    public List<CommodityCheck> getConditionSheetsWhereOnStateIsOne(){
        return conditionSheetCommodityMapper.getConditionSheetsWhereOnStateIsOne();
    }

    /**
     * 审核通过更新条件单状态
     */
    public void updateConditionSheetOnStateToTwo(String conditionSheetId){
        conditionSheetCommodityMapper.updateConditionSheetOnStateToTwo(conditionSheetId);
    }

    /**
     * 审核驳回更新条件单状态
     */
    public void updateConditionSheetOnStateToZero(String conditionSheetId){
        conditionSheetCommodityMapper.updateConditionSheetOnStateToZero(conditionSheetId);
    }

    /**
     * 审核通过删除条件单记录
     */
    public void deleteConditionSheetRecord(String conditionSheetId){
        conditionSheetCommodityMapper.deleteConditionSheetRecord(conditionSheetId);
    }

    /**
     * 审核通过过审条件单插入到商品表
     */
    public void insertConditionSheetIntoCommodity(String conditionSheetId, String commodityName, String commodityDescription, double commodityPrice){
        conditionSheetCommodityMapper.insertConditionSheetIntoCommodity(conditionSheetId,commodityName,commodityDescription,commodityPrice);
    }

    /**
     * 获取订单表中所有订单
     */
    public List<Order> selectAllOrders(String userId){
        return conditionSheetCommodityMapper.selectAllOrders(userId);
    }
    /**
     * 插入条件单商品审核数据
     *
     * @author 张展鹏
     */
    public int insertConditionSheetCommodityCheck(String conditionSheetId, String commodityName, int onState,
            String commodityDescription, double commodityPrice, String authorId){
        return conditionSheetCommodityMapper.insertConditionSheetCommodityCheck(conditionSheetId, commodityName, onState,
                                                                                commodityDescription,commodityPrice, authorId);
    }


    /**
     * 审核通过过审条件单插入运营数据表
     */
    public void insertNewConditionSheetOperationData() {
        conditionSheetCommodityMapper.insertNewConditionSheetOperationData();
    }

    /**
     * 条件单购买成功新增开通数
     */
    public void updateconditionSheetRegistration(String commodityId) {
        conditionSheetCommodityMapper.updateconditionSheetRegistration(commodityId);
    }
    // **************** 私有方法

}
